/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fix.it.source.fixit;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

/**
 *
 * @author Biserka
 */
@RequestScoped
@Named
public class ReportProblemIndexPresenter {
    @Inject
    private ReportProblemBean reportProblem;
    @Inject
    private AuthorityBean authorityBean;
    @Inject
    private MunicipalityBean municipalityBean;
    @Inject
    private ProblemTypeBean problemTypeBean;
    @Inject
    private StreetBean streetBean;
    @Inject
    private UserBean userBean;
    
    private String name;
    private String date;
    private Integer importance = 0;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getImportance() {
        return importance;
    }

    public void setImportance(Integer importance) {
        this.importance = importance;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }
    
     /* Problem */
    private Problem problem = new Problem();
    public Problem getProblem(){
        return problem;
    }
    public void setProblem(Problem p){
        this.problem = p;
    }
    public void action() throws ParseException{
        this.problem.setAuthorityid(authority);
        this.problem.setMunicipalityid(municipality);
        this.problem.setIssolved(0);
        this.problem.setProblemtypeid(problemType);
        this.problem.setStreetid(street);
        this.problem.setUserid(user);
        this.problem.setProblemname(this.name);
        try{
            this.problem.setReportdate(new Date());
        } catch(Exception err){ System.out.println("Error parsing date"); }
        this.problem.setImportance(this.importance);
        reportProblem.storeProblem(this.problem);
    }
    /* Authority */
    private Authority authority = new Authority();
    
    public Authority getAuthority() {
        return authority;
    }
    public void setAuthority(Authority authority) {
        this.authority = authority;
    }
    public Authority[] getAuthorities(){
        List<Authority> m = authorityBean.getAuthorities();
        Authority[] list = new Authority[m.size()];
        for(int i = 0; i < m.size(); i++){
            list[i] = m.get(i);
        }
        return list;
    }
    /* Municipality */
    private Municipality municipality = new Municipality();
    
    public Municipality getMunicipality() {
        return municipality;
    }
    public void setMunicipality(Municipality municipality) {
        this.municipality = municipality;
    }
    public Municipality[] getMunicipalities(){
        List<Municipality> m = municipalityBean.getMunicipalities();
        Municipality[] list = new Municipality[m.size()];
        for(int i = 0; i < m.size(); i++){
            list[i] = m.get(i);
        }
        return list;
    }
    /* Problem Type */
    private Problemtype problemType = new Problemtype();
    
    public Problemtype getProblemType() {
        return problemType;
    }
    public void setProblemType(Problemtype problemType) {
        this.problemType = problemType;
    }
    public Problemtype[] getProblemTypes(){
        List<Problemtype> m = problemTypeBean.getProblemTypes();
        Problemtype[] list = new Problemtype[m.size()];
        for(int i = 0; i < m.size(); i++){
            list[i] = m.get(i);
        }
        return list;
    }
    /* Street */
    private Street street = new Street();
    
    public Street getStreet() {
        return street;
    }
    public void setStreet(Street street) {
        this.street = street;
    }
    public Street[] getStreets(){
        List<Street> m = streetBean.getStreets();
        Street[] list = new Street[m.size()];
        for(int i = 0; i < m.size(); i++){
            list[i] = m.get(i);
        }
        return list;
    }
    /* User */
    private Localuser user = new Localuser();
    
    public Localuser getUser() {
        return user;
    }
    public void setUser(Localuser user) {
        this.user = user;
    }
    public Localuser[] getUsers(){
        List<Localuser> m = userBean.getLocalUsers();
        Localuser[] list = new Localuser[m.size()];
        for(int i = 0; i < m.size(); i++){
            list[i] = m.get(i);
        }
        return list;
    }
}
